<?php
class http_lib{

    static $timeout = 5;

    /**
     * 获取Http请求响应
     *
     * @param unknown_type $url
     * @param unknown_type $post
     * @return unknown
     */
    static function &get($url,$post=0){
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL,  $url);
        curl_setopt($ch, CURLOPT_POST, $post);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, self::$timeout);
        $ret = curl_exec($ch);
        curl_close($ch);
        return $ret;
    }

    /**
     * Post方式请求
     *
     * @param unknown_type $url
     */
    static function &post($url,$data){
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_TIMEOUT, self::$timeout);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_POST, 1);
        $ret = curl_exec($ch);
        curl_close($ch);
        return $ret;
    }


}
?>